package com.example.a97369.zyfupt_wkm306.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.a97369.zyfupt_wkm306.R;
import com.example.a97369.zyfupt_wkm306.activity.CMainActivity;
import com.example.a97369.zyfupt_wkm306.activity.FocusActivity;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by 97369 on 2017/5/28.
 */

public class Fragment6 extends Fragment {
    private Button btn_exit;
    private Button btn_collect,btn_focus;
    private TextView tv_username;
    private TextView tvinfo;
    private View view=null;
    private Context context;
    private String username="",tele="";//用户名密码
    private SharedPreferences sp;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
        //动态加载Fragment5的布局文件
        view=inflater.inflate(R.layout.fragment6,container,false);
        //获取布局上的控件，注意通过view获取
        tvinfo=(TextView)view.findViewById(R.id.textView_me);
        tv_username=(TextView)view.findViewById(R.id.textView_username);
        btn_collect=(Button)view.findViewById(R.id.button3);
        btn_focus=(Button)view.findViewById(R.id.button4);
        btn_collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.button3:
                        Intent intent = new Intent();
                        intent.setClass(getActivity(),CMainActivity.class);//forward为当前activity，forwardTarget为新的activity
                        startActivity(intent);
                        break;
                }
            }
        });
        btn_focus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.button4:
                        Intent intent = new Intent();
                        intent.setClass(context,FocusActivity.class);//forward为当前activity，forwardTarget为新的activity
                        startActivity(intent);
                        break;
                }
            }
        });
        sp=context.getSharedPreferences("login",MODE_PRIVATE);
        Toast.makeText(context, "加载我", Toast.LENGTH_SHORT).show();
        //返回动态生成的view
        readSP();
        tv_username.setText(username);
//        tvinfo.setText(tele);
        return view;
    }
    private void readSP() {
        username=sp.getString("username",null);
//        tele=sp.getString("tel",null);
    }

}
